<!--
+----------------------------------------------------------------------
| 友得云客  - 开启房产营销新纪元
+----------------------------------------------------------------------
| Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
+----------------------------------------------------------------------
| Licensed 友得云客不是自由软件 未经允许不可移除相关版权
+----------------------------------------------------------------------
| Author: www.youdeyunke.com
+----------------------------------------------------------------------
-->
<template>
    <div class="outer" v-cloak>
        <el-table :data="items" v-loading="loading" size="mini">
            <el-table-column label="名称" prop="name" width="200"></el-table-column>
            <el-table-column label="说明" prop="desc"></el-table-column>
            <el-table-column label="share Key" prop="key"></el-table-column>
            <el-table-column label="增加积分" prop="amount" width="100"></el-table-column>
            <el-table-column width="100">
                <template slot-scope="scope">
                    <el-button type="text" @click="settingHandle(scope.row)">设置</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-dialog :visible.sync="showForm" width="300px" v-loading="loading" :destroy-on-close="true" title="设置积分规则" :close-on-click-modal="false">
            <el-form label-position="left" v-if="item" label-width="60px">

                <el-form-item label="积分值">
                    <el-input type="number" v-model="item.amount"></el-input>
                </el-form-item>

            </el-form>
            <div slot="footer">
                <el-button size="mini" :loading="loading" :disabled="loading" @click="cancleHandle" icon="el-icon-close">取消</el-button>
                <el-button size="mini" :loading="loading" :disabled="loading" type="primary" @click="submitHandle" icon="el-icon-check">确定修改</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script>
import { getScoreConfigList, updateScoreConfig } from '@/api/score'
export default {
    data () {
        return {
            items: [],
            item: null,
            showForm: false,
            loading: false,
        };
    },
    props: {
    },
    components: {},

    mounted: function () {
        this.loadData()
    },

    computed: {
    },

    methods: {
        cancleHandle: function () {
            this.loadData()
            this.showForm = false
        },
        settingHandle: function (item) {
            this.showForm = true
            this.item = item
        },

        submitHandle: function () {
            var a = this.item.amount
            if (a <= 0) {
                this.$message.error('积分值不能小于等于0')
                return false
            }
            this.loading = true
            updateScoreConfig(this.item).then((res) => {
                this.loading = false
                if(res.code != 0){
                    return
                }
                this.$message.success("保存成功")
                
                this.loadData()
                this.showForm = false
            })
        },

        loadData: function () {
            this.loading = true
            getScoreConfigList().then((res) => {
                this.loading = false
                this.items = res.data
            })
        },
    }
};
</script>

<style scoped></style>